package com.example.pages;

import static org.junit.Assert.assertTrue;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.FindBy;

public class InternalPage extends AnyPage {

	@FindBy(xpath = "//a[contains(@href,'logout')]")
	public WebElement menuLogoutLink;

	@FindBy(xpath = "//a[contains (@href, 'profile')]")
	public WebElement menuMyProfileLink;

	@FindBy(css = "a[href ='http://localhost/php4dvd/']")
	public WebElement menuHomeLink;

	@FindBy(css = "a[href *='users']")
	public WebElement menuUserManagementLink;

	public UserPage gotoUserProfile() {
		menuMyProfileLink.click();
		return MyPageFactory.getPage(driver, UserPage.class);
	}

	public boolean isOnThisPage() {
		return menuLogoutLink.isDisplayed();
	}

	@Override
	void tryToOpen() {
		MyPageFactory.getPage(driver, LoginPage.class).loginWithValidCredentials("admin", "admin");
	}

	public void logout() {
		menuLogoutLink.click();
		// wait.until(visibilityOfElementLocated(By.linkText("Log out"))).click();
		// remove here as using page objects
		// driver.findElement(By.linkText("Log out")).click(); remove here as
		// wait was added
		assertTrue(
				"Could not close alert",
				closeAlertAndGetItsText().matches(
						"^Are you sure you want to log out[\\s\\S]$"));
	}

	public UsersPage gotoUserManagement() {
		menuUserManagementLink.click();
		return MyPageFactory.getPage(driver, UsersPage.class);
	}
	
	public void moveOnUserManagementLink() throws InterruptedException {
		driver.manage().window().maximize();
		Thread.sleep(2000);
		Actions theAction = new Actions(driver);
		theAction.moveToElement(menuUserManagementLink);
		theAction.build().perform();
		String backgroundColor = menuUserManagementLink.getCssValue("color");
		System.out.println("Color for navigated is "+backgroundColor);
		backgroundColor = menuMyProfileLink.getCssValue("color");
		System.out.println("Color for non navigated is "+backgroundColor);
	//	backgroundColor = menuHomeLink.getCssValue("color");
	//	System.out.println("Color for non navigated is "+backgroundColor);
	}
	
}
